<%--
  Created by IntelliJ IDEA.
  User: 骆鹏
  Date: 2017/7/27
  Time: 11:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>

<html>
<head>
    <title>事件上报</title>
    <meta name="viewport" content="width=device-width, initial-scale=0.3, user-scalable=0, minimum-scale=0, maximum-scale=5.0,user-scalable=yes">
    <link rel="stylesheet" href="/css/officialDocument/officialDocument.css">
    <link rel="stylesheet" href="/lib/layer/skin/default/layer.css">
    <link rel="stylesheet" href="/lib/laydate/need/laydate.css">
    <link rel="stylesheet" href="/lib/pagination/style/pagination.css">
    <link rel="stylesheet" href="/css/base.css">
    <script type="text/javascript" src="/lib/jQuery-File-Upload-master/jquery-1.8.3.min.js"></script>
    <script src="/lib/layer/layer.js?20201106"></script>
    <script src="/js/base/base.js"></script>
    <script src="/lib/laydate/laydate.js"></script>
    <script src="/lib/jquery-validate.js"></script>
    <script src="/lib/validate-mothods.js"></script>
    <script src="/lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <script src="/lib/laydate/laydate.js"></script>
    <script src="/js/laydate/laydate.js"></script>
    <script src="/js/workflow/work/workform.js"></script>
    <script src="/js/jquery/jquery.cookie.js"></script>

</head>
<body>
<div class="cont_form" style="display: none"></div>
<script>




    function buildFormData(){
        var arr = {};
        $(".cont_form").find('.form_item').each(function(i,v){
            var _this = $(this);
            arr[_this.attr('title')] = _this.attr('name');
        });
        return arr;
    }


    var me=null;

    var user_id='';

    var formData=null;
    var fromDataRejects=null;
    var modifydata=null;
    var runids=null;
    var runnames=null;
    var beginTime=null;
    var beginUser=null;
    var prcsId=null;
    var flowPrcs=null;
    var formLength;
    var tableId=null;
    var jingbanUser=null;
    var fromDataRejectsTwo=null;
    var modifydataTwo=null;









    var userIdValue='';
    var eventTimeValue='';
    var eventInfoValue='';





    function alldata(tableIds,newshenpirens,eventInfoNames,infoNamess,userIdValues,eventTimeValues,eventInfo) {
        tableId=tableIds;
        newshenpiren=newshenpirens;
        eventInfoName=eventInfoNames;
        infoNames=infoNamess;
         eventInfos=eventInfo
        userIdValue=userIdValues;
        eventTimeValue=eventTimeValues;
        eventInfoValue=eventInfoNames;



        $.when(
            $.get('/workflow/work/workfastAdd',{flowId:201,runId:'',prcsId:1,flowStep:1},function (json) {
                if(json.flag){
                    runids=json.object.flowRun.runId;
                    runnames=json.object.flowRun.runName;
                    beginTime=json.object.flowRun.beginTime;
                    beginUser=json.object.flowRun.beginUser;
                    prcsId=json.object.flowRunPrcs.prcsId;
                    flowPrcs=json.object.flowRunPrcs.flowPrcs;

                    $.get('/gridEventParting/updateByPrimaryKeySelective',{
                        rumId:runids,eventId:tableId
                    },function (json) {
                    },'json')
                    workForm.init({
                            formhtmlurl:'../../workflow/work/workfastAdd',//URL
                            resdata:{
                                flowId:201,
                                runId:runids,
                                prcsId:prcsId,
                                flowStep:1
                            },
                            flowStep:prcsId,//预览
                            target:'.cont_form'},
                        function (data,option) {

                            var fromDataReject = buildFormData();
                            var form_item=$('.cont_form .form_item');
                            var realData=[];
                            var radioArr = {};
                            var modifydatas =[];
                            formLength=option.formLength;
                            var flag = false;
                            for(var i=0;i<form_item.length;i++){
                                var baseData={};
                                var value="";
                                var obj = form_item.eq(i);
                                var datatype = obj.attr("data-type");
                                var key=obj.attr("name");
                                var ismust = obj.attr('ismust');
                                if(datatype=="select"){
                                    value= obj.val()==0?'':form_item.eq(i).val();
                                }else if(datatype=="textarea" || datatype=="text"  ){
                                    value=obj.val();
                                }else if(datatype=="checkbox"){
                                    value=obj.attr('title');
                                }else if(datatype=="macros"){
                                    if(obj.attr('type') == "text"){
                                        value= obj.val();
                                    }else{
                                        if(obj.val() > -1){
                                            value = obj.val()+'_'+obj.find("option:selected").text();

                                        }

                                    }
                                }else if(datatype == "radio"){
                                    var name = obj.attr('name');
                                    if(!radioArr[obj.attr('name')]){
                                        radioArr[obj.attr('name')] = true;
                                        if($("input[name='"+name+"']:checked").length>0){
                                            value= $("input[name='"+name+"']:checked").val();
                                        }else{
                                            value = "";
                                        }
                                    }else{
                                        continue;
                                    }
                                }else if(datatype == "macrossign"){
                                    value= obj.html();

                                }else if(datatype == "imgupload"){
                                    var url = obj.attr('src');

                                    if(url!='/img/icon_uploadimg.png'){
                                        value= url;
                                    }


                                }else{
                                    value = obj.val();
                                }

                                if(ismust == 'true' && value == ""){
                                    flag = true;
                                    layer.msg('<fmt:message code="main.th.PleaseFill" />'+obj.attr('title'), {icon: 1});
                                    break;
                                }
                                if( value!=null){
                                    baseData["key"]=key;
                                    baseData["value"]=value;

                                    if(baseData["key"]=="DATA_3"){
                                        baseData["value"]=infoNames;
                                    }else if(baseData["key"]=="DATA_54"){
                                        baseData["value"]=eventInfoName;
                                    }else if(baseData["key"]=="DATA_21"){
                                        baseData["value"]=eventInfos;
                                    }
                                    realData.push(baseData);
                                }
                                if(value != ''){

                                    modifydatas.push(baseData);
                                }
                            }


                            formData=JSON.stringify(realData);
                            fromDataRejectsTwo=fromDataReject;
                            modifydataTwo=modifydatas;
                            datacol()
                        })
                }
            },'json')

        )

    }




    var newshenpiren=null;
    var infoNames=null;
    var eventInfoName=null;


    //    alldata(404,'argaergaer','滨湖社区',204,208,'2017-10-28 10:53:23')





    function datacol() {
        (function (fn) {
            $.get('/flowhook/selectByFlowId?folwId=201',function (json) {
                if(json.flag){
                    var arr=json.object.map.split(',');
                    for(var i=0;i<arr.length;i++){
                        if(i<arr.length-1) {
                            var objrct = {};
                            objrct.key = fromDataRejectsTwo[arr[i].split('=>')[1]]
//                                                    if(arr[i].split('=>')[1]=='DATA_11'){
//                                                         continue;
//                                                    }
                            objrct.value =(function () {
//                                                        if(arr[i].split('=>')[0]=='USER_ID'){
//                                                            return userIdValue
//                                                        }else
                                if(arr[i].split('=>')[0]=='EVENT_TIME'){
                                    return eventTimeValue
                                }else if(arr[i].split('=>')[0]=='EVENT_INFO'){
                                    return  eventInfoValue
                                }else {
                                    return ''
                                }
                            })()
                            modifydataTwo.push(objrct)
                        }
                    }
                    modifydata=JSON.stringify(modifydataTwo);
                    fromDataRejects=JSON.stringify(fromDataRejectsTwo)
                    fn()
                }
            },'json')
        })(function () {
            $.post('/workflow/work/nextwork',{
                flowId:201,runId:runids,runName:runnames,
                beginTime:beginTime,beginUser:beginUser,
                prcsId:prcsId,flowPrcs:flowPrcs,
                tableName:'grid_event',tabId:tableId,formdata:formData,
                fromDataReject:fromDataRejects,modifydata:modifydata,
                formLength:formLength
            },function (json) {
                if(json.flag){

                    (function (fn) {
                        $.get('/workflow/work/findbranch',{
                            flowId:201, flowPrcs:'1',
                            runId:runids
                        },function (json) {
                            if(json.flag){
                                jingbanUser=json.object.prcsUser.split(',');
                                var num=0;
                                for(var i=0;i<jingbanUser.length;i++){
                                    if(jingbanUser[i]==newshenpiren){
                                        fn(newshenpiren)
                                        break;
                                    }else {
                                        num++;
                                    }
                                }
                                if(num==jingbanUser.length){
                                    var u = navigator.userAgent;
                                    if(u.indexOf('Android') > -1 || u.indexOf('Linux') > -1){
                                        window.Android.EventCallback('网格信息设置与流程的审批人不一致');
                                    }else {

                                        iOS('网格信息设置与流程的审批人不一致')
                                    }





//                                    if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
//                                        alert('ssss')
//                                        EventCallback('网格信息设置与流程的审批人不一致')
//                                    } else if (/(Android)/i.test(navigator.userAgent)) {
//                                        window.Android.EventCallback('网格信息设置与流程的审批人不一致');
//                                    }
                                }
                            }

                        },'json')
                    })(function (newshenpiren) {
                        var smsTypes='';
                        var smsTypesArr=$('.addactiveClass');
                        for(var i=0;i<smsTypesArr.length;i++){
                            if($(smsTypesArr[i]).hasClass('active')){
                                smsTypes+=$(smsTypesArr[i]).attr('data-id')+','
                            }else {
                                smsTypes+=','
                            }
                        }



                        $.post('/workflow/work/saveWork',{
                            flowId:201,runId:runids,runName:runnames,
                            beginTime:beginTime,beginUser:beginUser,
                            prcsId:prcsId,flowPrcs:'2',
                            prcsflag:1,jingbanUser:newshenpiren+",",
                            tableName:'grid_event',tabId:tableId,smsType:smsTypes
                        },function (json) {
                            if(json.flag){
                                var u = navigator.userAgent;
                                if(u.indexOf('Android') > -1 || u.indexOf('Linux') > -1){
                                    window.Android.EventCallback('ok');
                                }else {

                                    iOS('ok')
                                }



//                                if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
//                                    alert('ssss')
//                                    EventCallback('ok');
//                                } else if (/(Android)/i.test(navigator.userAgent)) {
//                                    window.Android.EventCallback('ok');
//                                }



//                                $.layerMsg({content:'转交成功！',icon:1},function () {
//                                });
                            }else {


                                var u = navigator.userAgent;
                                if(u.indexOf('Android') > -1 || u.indexOf('Linux') > -1){
                                    window.Android.EventCallback('errey');
                                }else {

                                    iOS('errey')
                                }


//                                if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
//                                    alert('ssss')
//                                    EventCallback('errey')
//                                } else if (/(Android)/i.test(navigator.userAgent)) {
//                                    window.Android.EventCallback('errey');
//                                }

                            }
                        },'json')
                    })


                }else {
                    var u = navigator.userAgent;
                    if(u.indexOf('Android') > -1 || u.indexOf('Linux') > -1){
                        window.Android.EventCallback('errey');
                    }else {

                        iOS('errey')
                    }



//                    if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
//                        EventCallback('errey')
//                    } else if (/(Android)/i.test(navigator.userAgent)) {
//                        window.Android.EventCallback('errey');
//                    }



                }
            },'json')
        })
    }


    //    alldata('313','139','1123','石园北二社区','139','2017-10-23 10:29:30')









</script>
</body>
</html>
